Vue.component("yl-table", {
  template: `<div>
  <el-form :inline="true" :form="form">
    <el-form-item>
      <el-input v-model="form.ID_Name" placeholder="请输入账号名称" @keyup.enter="onSerach"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSerach">查询</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="tableData" stripe border height="calc(100vh - 140px)" style="width: 100%">
    <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
    <el-table-column prop="User_Number" label="账号"></el-table-column>
    <el-table-column prop="Pass_Ward" label="密码"></el-table-column>
    <el-table-column prop="ID_Name" label="姓名"></el-table-column>
    <el-table-column align="center" label="权限" width="100">
      <template v-slot="{row}">
        <el-tag size="small" v-if="row.Admin_Type=='2'">系统管理员</el-tag>
        <el-tag size="small" v-else-if="row.Admin_Type=='1'">管理员</el-tag>
        <el-tag size="small" v-else-if="row.Admin_Type=='0'">普通用户</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="Enterprise_Name" label="所属企业"></el-table-column>
    <el-table-column label="操作" width="300">
    </el-table-column>
  </el-table>
  <div style="display: flex;align-items: center;justify-content: space-between;">
    <el-pagination background v-show="total > 0" @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="form.page" :page-sizes="[10, 20, 30, 50]" :page-size="form.limit"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
    <el-switch v-model="value" active-text="开启设置模式"></el-switch>
  </div></div>`,
  data() {
    return {
      form: {
        page: 1, //页数
        limit: 10, //每页数据条数
      },
      total: 0,
      tableData: [],
      prop: {},
      value: "",
    };
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    onSerach() {
      //查询方法
      this.getList(this.form);
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      console.log(`${DomainName}/UserAllAction?token=${$.cookie("token")}`);
      const that = this;
      $.ajax({
        type: "POST",
        url: `${DomainName}/UserAllAction?token=${$.cookie("token")}`,
        data,
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success") {
            that.tableData = Result.tableData;
            that.total = parseInt(Result.limit);
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json",
      });
    },
    Add() {
      window.location.href = "./Add.html";
    },
  },
});

new Vue({
  el: "#app",
  data() {
    return {
      form: {
        page: 1, //页数
        limit: 10, //每页数据条数
        ID_Name: "", //用户编号
      },
      formData: {},
      total: 0,
      tableData: [], //表格数据
      dialogTableVisible: false,
      value: false,
    };
  },
  mounted() {
    this.getList(this.form);
    this.getData();
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    onSerach() {
      //查询方法
      this.getList(this.form);
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    tableCellStyle({ row, column, rowIndex, columnIndex }) {
      if (row.Admin_Type == "2") return { backgroundColor: "yellowgreen" };
    },
    getList(data) {
      console.log(`${DomainName}/UserAllAction?token=${$.cookie("token")}`);
      let System_SerialNumber = sessionStorage.getItem("System_SerialNumber");
      let Enterprise_Info_SerialNumber = sessionStorage.getItem(
        "Enterprise_Info_SerialNumber"
      );
      console.log(Enterprise_Info_SerialNumber);
      console.log(System_SerialNumber);
      // return;
      //换页方法
      const _this = this;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        type: "get",
        // url: `${DomainName}/UserAllAction?token=${$.cookie("token")}`,
        // url: "http://192.168.10.92:8087/Enterprise/getEmployerByEnterprise",
        url: "https://service.kdddy.cn/donghuiForRequest/Enterprise/getEmployerByEnterprise",
        data: {
          eid: Enterprise_Info_SerialNumber,
          sid: System_SerialNumber,
        },
        success: function (Result) {
          console.log(Result);

          if (Result.Status == "success") {
            console.log(1111);

            // Result.tableData.unshift(...Result.tableData.splice(Result.tableData.findIndex(i => i.Admin_Type == '2'),1));
            _this.tableData = Result.Data;
            _this.total = parseInt(Result.limit);
          }
        },
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        dataType: "json",
      });
    },
    getData() {
      $.ajax({
        type: "POST",
        url: `${DomainName}/getInquirySQLAction?token=${$.cookie("token")}`,
        data: {
          Data: `SELECT enterprise_info.Enterprise_Name As Enterprise_Name,
            enterprise_info.Tax_Number As Tax_Number
            FROM enterprise_info`,
        },
        success: function (Result) {
          console.log(Result);
        },
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        dataType: "json",
      });
    },
    addEnterprise() {
      window.location.href = "./Add.html";
    },
    handleMenu(row) {
      console.log(row);

      sessionStorage.setItem("zh", row.User_Number);
      sessionStorage.setItem("qy", row.Enterprise_Info_SerialNumber);
      // window.location.href = "Menu.html?User_Number=" + row.User_Number;
      window.location.href = "./Menu.html";
    },
    handleMenu2() {
      let yg = 1;
      sessionStorage.setItem("yg", yg);
      window.location.href = "./newMenu.html";
    },
    handleExamine(User_Number) {
      const this_ = this;
      $.ajax({
        type: "POST",
        url: `${DomainName}/getInquiryIDOriginal?token=${$.cookie("token")}`,
        data: {
          Primary_Key_Name: "User_Number",
          Primary_Key: User_Number,
          Data: "system_user_info",
        },
        success: function (Result) {
          console.log(Result);
          this_.formData = Result[0];
          this_.dialogTableVisible = true;
        },
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        dataType: "json",
      });
    },
    UpdateApplication(i) {
      const this_ = this;
      this_.formData.Examine = i;
      if (i == 0) {
        this_.formData.Authentication = 1;
      }
      $.ajax({
        type: "POST",
        url: `${DomainName}/getEditAction?token=${$.cookie("token")}`,
        data: {
          Data: JSON.stringify({
            Modify: { system_user_info: [this_.formData] },
          }),
        },
        success: function (Result) {
          console.log(Result);
          if (Result.Status == "success" && i == 2) {
            this_.$message({
              message: "已拒绝对方申请",
              type: "warning",
            });
            this_.dialogTableVisible = false;
            this_.getList(this_.form);
          } else if (Result.Status == "success" && i == 0) {
            this_.$message({
              message: "已同意对方申请",
              type: "success",
            });
            sessionStorage.setItem("User_Number", this_.formData.User_Number);
            window.location.href =
              "./Menu.html?User_Number=" + this_.formData.User_Number;
          } else {
            this_.$message({
              message: "系统异常,请稍后重试",
              type: "error",
            });
          }
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json",
      });
    },
    handleEdit(EnterpriseInfo_SerialNumber) {
      sessionStorage.setItem(
        "EnterpriseInfo_SerialNumber",
        EnterpriseInfo_SerialNumber
      );
      window.location.href =
        "./Edit.html?EnterpriseInfo_SerialNumber=" +
        EnterpriseInfo_SerialNumber;
    },
  },
});
